home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / moveNurbsCurveSeam.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.7 KB  |  177 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Author:         Martin Watt (mwatt@aw.sgi.com)
  22. //
  23. // Description:
  24. //   Given a selected periodic curve, move the seam to the selected
  25. //   point
  26. //
  27. //   Does not reorder weights on rational curves
  28. //   Requires uniform knot sequences
  29. //   
  30.  
  31. proc float[] getNurbsCurveKnots(
  32.     string $crvName )
  33. //
  34. //  Description :
  35. //
  36. {
  37.     float $knots[] ;
  38.     string $infoNode ;
  39.  
  40.     // create info Node.
  41.     if( catch( $infoNode = `createNode curveInfo` ) ) {
  42.         return $knots ;
  43.     }
  44.  
  45.     // connect curve on to the info node.
  46.     //
  47.     string $outAttr = $crvName + ".local" ;
  48.     string $inAttr = $infoNode + ".ic" ;
  49.     connectAttr $outAttr $inAttr ;
  50.  
  51.     // read the knots.
  52.     //
  53.     $outAttr = $infoNode + ".knots" ;
  54.     $knots = `getAttr $outAttr` ;
  55.  
  56.     // delete curve info node.
  57.     //
  58.     delete $infoNode ;
  59.  
  60.     // return the knots.
  61.     //
  62.     return $knots;
  63. }
  64.  
  65. proc doMoveCurveSeam(string $crv, int $nspansToMove)
  66. {
  67.     // get the curve size
  68.     int $spans = eval("getAttr " + $crv + ".spans");
  69.     int $degree = eval("getAttr " + $crv + ".degree");
  70.     int $form = eval("getAttr " + $crv + ".form");
  71.     
  72.     // get number of CVs
  73.     int $ncvs = $spans;
  74.  
  75.     // array to hold shifted CVs
  76.     float $cvs[];
  77.  
  78.     // array to hold a single CV
  79.     float $cv[3];
  80.  
  81.     // move CVs and store in array
  82.     int $u = 0; 
  83.     for($u = 0; $u<$ncvs; $u++) {
  84.         $cv = eval("xform -q -ws -t " + $crv + ".cv[" + $u + "]");
  85.         int $newU = $u - $nspansToMove;
  86.         if($newU < 0) $newU = $newU + $ncvs;
  87.         for($dim=0; $dim<3; $dim++) {
  88.             $cvs[3*$newU + $dim] = $cv[$dim];
  89.         }
  90.     }
  91.  
  92.     // copy reordered CVs from array back to curve
  93.     for($u = 0; $u<$ncvs; $u++) {
  94.         for($dim=0; $dim<3; $dim++) {
  95.             $cv[$dim] = $cvs[3*$u + $dim];
  96.         }
  97.         eval("xform -ws -t " + $cv[0] + " " + $cv[1] + " " + $cv[2] + " " 
  98.              + $crv + ".cv[" + $u + "]");
  99.     }
  100.  
  101.     return;
  102. }
  103.  
  104. global proc moveNurbsCurveSeam() {
  105.  
  106.     // get all selected items
  107.     string $items[] = `ls -sl`;
  108.     
  109.     // Run filter to select only NURBS curve points
  110.     global int $gSelectCurveParmPointsBit ;
  111.     
  112.     string $crvList[] = `filterExpand -ex true 
  113.         -sm $gSelectCurveParmPointsBit`;
  114.     int $len = size($crvList) ;
  115.     if( $len != 1 ) {
  116.         error ("Select a single curve point");
  117.         return;
  118.     }
  119.  
  120.     // get curve from selection
  121.     string $crv[] = `listRelatives -parent $items[0]`;
  122.  
  123.     // get the knot value of the selected isoparm
  124.     string $buffer[];
  125.     tokenize $crvList[0] "[|]" $buffer;
  126.      float $selectedKnot = $buffer[1];
  127.  
  128.     // get degree (U or V)
  129.     int    $deg = eval("getAttr " + $crv[0] + ".degree");
  130.     int    $form = eval("getAttr " + $crv[0] + ".form");
  131.  
  132.     // check that the curve is really periodic!!
  133.     if(2 != $form) {
  134.         error ("Surface is not periodic, no seam to move");
  135.         return;
  136.     }
  137.  
  138.     // get the knots
  139.     float $knots[] = getNurbsCurveKnots($crv[0]);
  140.     int $numKnots = size($knots);
  141.  
  142.     // check that the knots are indeed uniform
  143.     int $i;
  144.     float $interval = $knots[1] - $knots[0];
  145.     for($i=2; $i<$numKnots; $i++) {
  146.         float $newInterval = $knots[$i] - $knots[$i-1];
  147.         if(abs($newInterval - $interval) > 0.01*$interval) {
  148.             error ("Knots are not uniform, cannot move seam");
  149.         }
  150.     }
  151.  
  152.     // find the closest surface knot to the selected isoparm
  153.     int $closestKnot = $deg-1;
  154.     float $closestDistance = abs($selectedKnot - $knots[$deg-1]);
  155.     int $i;
  156.     for($i=$deg; $i<=($numKnots-$deg); $i++) {
  157.         float $distance = abs($knots[$i] - $selectedKnot);
  158.         if($distance < $closestDistance) {
  159.             $closestDistance = $distance;
  160.             $closestKnot = $i;
  161.         }
  162.     }
  163.  
  164.     // check for zero move
  165.     if(($deg-1) == $closestKnot || ($numKnots-$deg) == $closestKnot) {
  166.         error ("Seam is already at this location, no change will be made");
  167.         return;
  168.     }
  169.  
  170.      // do the move
  171.     int $numSpansToMove = $closestKnot - ($deg-1);
  172.     doMoveCurveSeam($crv[0], $numSpansToMove);
  173.         
  174.     return;
  175. }
  176.  
  177.